//
//  ViewController.m
//  取数据
//
//  Created by dllo on 15/11/10.
//  Copyright (c) 2015年 JEH. All rights reserved.
//

#import "ViewController.h"
#import "FirstModel.h"
#import "UIImageView+WebCache.h"



@interface ViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) NSArray *dataSource;
@property (nonatomic, retain) FirstModel *first;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    NSArray *array = [[NSArray alloc] initWithContentsOfFile:@"/Users/dllo/Downloads/mov副本.plist"];
    NSMutableArray *mutable = [[NSMutableArray alloc] initWithCapacity:0];
    for (NSDictionary *dic in array) {
        FirstModel *first = [[FirstModel alloc] initWithDataSource:dic];
        [mutable addObject:first];
    }
    self.dataSource = [[NSArray alloc] initWithArray:mutable];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:tableView];
    [tableView release];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _dataSource.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[_dataSource[section] datas] count];
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    SecondModel *second = [[SecondModel alloc] init];
    _first = _dataSource[indexPath.section];
    second = _first.datas[indexPath.row];
    cell.textLabel.text = second.title;
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:second.img] placeholderImage:[UIImage imageNamed:@"http://img3.douban.com/view/movie_poster_cover/lpst/public/p2267236332.jpg"]];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end















